package com.lei.chinese_herbal_medicine.Controller;


import com.lei.chinese_herbal_medicine.Entity.HerbType;
import com.lei.chinese_herbal_medicine.Entity.Result;
import com.lei.chinese_herbal_medicine.Service.HerbTypeService;
import com.lei.chinese_herbal_medicine.Util.UUIDUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (HerbType)表控制层
 *
 * @author makejava
 * @since 2024-01-18 10:05:27
 */
@RestController
public class HerbTypeController {
    /**
     * 服务对象
     */
    @Resource
    private HerbTypeService herbTypeService;
    @Resource
    Result result;
    @GetMapping("/getModelHerbType")
    public Result getModelHerbType(String id){
        Map modelHerbTypeNum=herbTypeService.selectHerbTypeByModelId(id);
        Map map=new HashMap();
        map.put("modelHerbTypeNum",modelHerbTypeNum);
        result.setData(map);
        result.setCode(200);
        result.getData().put("message","查询成功");
        return result;
    }

    @GetMapping("/selectByHerbType")
    public Result selectByHerbType(HerbType record){
        List<HerbType> list=herbTypeService.selectByHerbType(record);
        result.setCode(200);
        result.setList(list);
        Map map=new HashMap();
        map.put("message","查询成功");
        result.setData(map);
        return result;
    }



//    @GetMapping("/addHerbType")
    public Result addHerbType(){
//        String[] types = {"解表药","清热药", "祛风湿药",  "利尿渗湿药", "化痰止咳药","理气药","活血药","止血药","消食药","驱虫药","泻下药","清暑药","祛寒药","安神、镇痉药","补益药","收敛药","软坚药","外用药"};
        String[] types = {};
        List< HerbType> herbTypes=new ArrayList<>();
        HerbType herbType=null;
        for (String type : types) {
            herbType=new HerbType(UUIDUtil.fastSimpleUUID(),type);
            herbTypes.add(herbType);
        }
        boolean flag=herbTypeService.insertHerbType(herbTypes);
        if (flag){
            result.setCode(200);
            Map map=new HashMap();
            map.put("message","添加成功");
            result.setData(map);
        }else{
            result.setCode(403);
        }
        return result;
    }

}

